﻿using EV.EventBus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ZoneLine.ViewModels;

namespace ZoneLine.Views
{
    /// <summary>
    /// WorkSituationView.xaml 的交互逻辑
    /// </summary>
    public partial class WorkSituationView : Window
    {
        public WorkSituationView()
        {
            InitializeComponent();
            this.Closed += WorkSituationView_Closed;
                
            MessageCenter.Subscribe(nameof(WorkSituationViewModel), Guid.NewGuid().ToString(), (s) =>
            {
                if (s.Source.Payload is string ss)
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        var viewModel = this.DataContext as WorkSituationViewModel;
                        if (viewModel != null)
                        {
                            viewModel.AbsScanCode = ss;
                        }
                    });
                }
                return Task.CompletedTask;
            });
        }

        private void WorkSituationView_Closed(object sender, EventArgs e)
        {
            MessageCenter.Unsubscribe(nameof(WorkSituationViewModel));
        }

    }
}
